#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2016-12-18 11:50:09
# @Author  : PiaoYun (piaoyunsoft@163.com)
# @Link    : http://www.dllhook.com
# @Version : $Id$
  

#from twisted.internet import protocol, reactor, endpoints  

from twisted.internet.protocol import Protocol
from twisted.internet.protocol import Factory
from twisted.internet import reactor
from sys import stdout

class Echo(Protocol):
    def dataReceived(self,data):
        stdout.write(data)
        self.transport.write(data)

if __name__ == '__main__':
    f = Factory()
    f.protocol = Echo
    reactor.listenTCP(1234, f)
    reactor.run()


'''
class Echo(protocol.Protocol):  
    def dataReceived(self, data):  
        self.transport.write(data)  
  
class EchoFactory(protocol.Factory):  
    def buildProtocol(self, addr):  
        return Echo()  
  
if __name__ == '__main__':  
    endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory())  
    reactor.run() 
'''

